package com.yizhuoyan.his.service.pharmacyoperator.ServiceImpl;

import com.yizhuoyan.his.ao.CaseRegistrationRecordAo;
import com.yizhuoyan.his.dao.CaseRegistrationRecordDao;
import com.yizhuoyan.his.dao.DocHerbalPrescriptionDetailDao;
import com.yizhuoyan.his.dao.DocPrescriptionDetailDao;
import com.yizhuoyan.his.dao.HosDrugsDao;
import com.yizhuoyan.his.entity.CaseRegistrationRecordEntity;
import com.yizhuoyan.his.entity.DocHerbalPrescriptionDetailEntity;
import com.yizhuoyan.his.entity.DocPrescriptionDetailEntity;
import com.yizhuoyan.his.entity.HosDrugsEntity;
import com.yizhuoyan.his.qco.CaseRegistrationRecordQco;
import com.yizhuoyan.his.service.pharmacyoperator.DrugSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.List;


@Slf4j
@Service
public class DrugSendServiceImpl implements DrugSendService {
    @Autowired
    CaseRegistrationRecordDao dao;
    @Autowired
    HosDrugsDao hDao;
    @Autowired
    DocPrescriptionDetailDao dDao;
    @Autowired
    DocHerbalPrescriptionDetailDao dHDao;
    @Override
    public List<CaseRegistrationRecordEntity> queryCaseRegistrationRecord(@NonNull CaseRegistrationRecordQco qco) throws Exception {
       //清理参数
        CaseRegistrationRecordQco qco1 = new CaseRegistrationRecordQco();
        if(qco!=null){
            String realname=null;
            String no =null;
            if(qco.getRealname()!=null&&qco.getRealname().trim().length()!=0){
                realname=qco.getRealname()+"%";
                qco1.setRealname(realname);
            }
            if (qco.getNo()!=null&&qco.getNo().trim().length()!=0){
                no= qco.getNo()+"%";
                qco1.setNo(no);
            }
        }
        //执行逻辑
        List<CaseRegistrationRecordEntity> caseRegistrationRecordEntities = dao.selectCaseRegistrationRecord(qco1);
        if(caseRegistrationRecordEntities==null){
            log.trace("未查询到患者");
            throw new NullPointerException();
        }
        return caseRegistrationRecordEntities;
    }


    @Override

    public List<HosDrugsEntity> queryPrescriptionDetailsDrugs( Long id) throws Exception {
        //清理参数
        //执行逻辑
        List<HosDrugsEntity> hosDrugsEntities = hDao.selectHerbalPrescriptionDetailDrugById(id);
        if(hosDrugsEntities==null) {
            log.debug("查询患者的中药为空");
            throw  new NullPointerException();
        }
        //组装业务
        return hosDrugsEntities;
    }

    @Override
    public List<HosDrugsEntity> queryHerbalPrescriptionDetailsDrugs(Long id) throws Exception {
        //清理参数
        //执行逻辑
        List<HosDrugsEntity> hosDrugsEntities = hDao.selectPrescriptionDetailDrugById(id);
        if(hosDrugsEntities==null){
            log.debug("查询患者西药为空");
            throw  new NullPointerException();
        }
        //组装业务
        return hosDrugsEntities;
    }

    @Override
    public List<DocHerbalPrescriptionDetailEntity> queryHerbalPrescriptionDetails( Long id) throws Exception {
        //清理参数
        //执行逻辑
        List<DocHerbalPrescriptionDetailEntity> docHerbalPrescriptionDetailEntities = dHDao.selectHerbalPrescriptionDetailById(id);
        if(docHerbalPrescriptionDetailEntities==null){
            log.debug("查询患者中药处方为空");
            throw  new NullPointerException();
        }
        //组装业务
        return docHerbalPrescriptionDetailEntities;
    }

    @Override
    public List<DocPrescriptionDetailEntity> queryPrescriptionDetails(Long id) throws Exception {
        //清理参数
        //执行逻辑
        List<DocPrescriptionDetailEntity> docPrescriptionDetailEntities = dDao.selectPrescriptionDetailById(id);
        if(docPrescriptionDetailEntities==null){
            log.debug("查询患者西药处方为空");
            throw  new NullPointerException();
        }
        //组装业务
        return docPrescriptionDetailEntities;
    }



}
